<!DOCTYPE html>
<?php
error_reporting(E_ALL || ~E_NOTICE);
$username = $_POST['username'];
$password = $_POST['password'];
if (!isset($_POST['username']) || !isset($_POST['password'])) {
    ?>
    <html>

    <head>
        <meta charset="UTF-8">
        <title>Bootstrap Snippet: Login Form</title>

        <link rel="stylesheet prerender" href="css/bcss/bootstrap.min.css">
        <link rel="stylesheet" href="css/style.css">

    </head>

    <body class="huibg">
        <div class="wrapper">
            <form class="form-signin" method="post" action="login.php">
                <h2 class="form-signin-heading">登录账号</h2>
                <input type="text" class="form-control" name="username" placeholder="账号" required="" autofocus />
                <input type="password" class="form-control" name="password" placeholder="密码" required="" />
                <label class="checkbox">
                        <input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> 保存密码
                    </label>
                <button class="btn btn-lg btn-primary btn-block"> 登 录</button>

            </form>
        </div>



    </body>

    </html>
    <?php
} else {
    error_reporting(E_ALL || ~E_NOTICE);
    $link = mysqli_connect("localhost", "root", "123456");
    if (!$link) {
        echo "GG";
        exit;
    }

    $selected = mysqli_select_db($link, "sample");
    if (!$selected) {
        echo"selet GG";
        exit;
    }

    $query = "select count(*) from archives where 
             stu_number = '" . $username . "' and 
             password = '" . $password . "'";
    $result = mysqli_query($link, $query);
    if (!$result) {
        echo "cannot run";
        exit;
    }
    $row = mysqli_fetch_row($result);
    $count = $row[0];


    if ($count > 0) {
        session_start();
        $_SESSION['one'] = $username;
        $_SESSION['two'] = "1";
        header("Location:index.php");
    } else {
        echo"<script>alert('密码或用户名错误');location.href='login.php'</script>";
    }
}
?>
